package com.huiminpay.merchant.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huiminpay.common.cache.domain.BusinessException;
import com.huiminpay.merchant.api.AppService;
import com.huiminpay.merchant.common.intercept.util.SecurityUtil;
import com.huiminpay.merchant.convert.AppCovert;
import com.huiminpay.merchant.dto.AppDTO;
import com.huiminpay.merchant.entity.App;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * @ClassName : AppController
 * @Author : qawine
 * @Date: 2021/3/24 20:07
 * @Description : 商户应用接口
 */
@Api(value = "商户平台-应用管理", tags = "商户平台-应用相关", description = "商户平台-应用相关")
@RestController
public class AppController {
    @Reference
    private AppService appService;
    @ApiOperation("商户创建应用")
    @ApiImplicitParams({@ApiImplicitParam(name = "app", value = "应用信息",
            required = true, dataType = "AppDTO", paramType = "body")})
    @PostMapping(value = "/my/apps")
    public AppDTO createApp(@RequestBody AppDTO app) {
        Long merchantId = SecurityUtil.getMerchantId();
        return appService.createApp(merchantId, app);
    }

    @ApiOperation("查询商户下的应用列表")
    @GetMapping("/my/apps")
    public List<AppDTO> queryAppByMerchantId() {
        Long merchantId = SecurityUtil.getMerchantId();
        return appService.queryAppByMerchantId(merchantId);
    }

   @ApiOperation("根据appid获取应用的详细信息")
   @GetMapping("/my/apps/{appId}")
    public AppDTO selectAppById(@PathVariable String appId)  {
       return appService.selectAppById(appId);
    }
}